<template>
  <el-row class="tac">
    <el-col :span="12">
      <el-menu
          style="width: 200px;min-height: calc(100vh - 50px)"
          active-text-color="#4169E1"
          background-color="#F5FFFA"
          class="el-menu-vertical-demo"
          router
          :default-active="path"
          text-color="#000000"
      >
        <el-sub-menu index="1" v-if="user.role === '1'">
          <template #title><span>系统管理</span></template>
          <el-menu-item index="user">用户管理</el-menu-item>
        </el-sub-menu>
        <el-menu-item index="book">图书管理</el-menu-item>
        <el-menu-item index="category">分类管理</el-menu-item>
        <el-menu-item index="home">地区统计</el-menu-item>
        <el-menu-item index="news">文章管理</el-menu-item>
      </el-menu>
    </el-col>
  </el-row>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "Aside",
  data(){
    return{
      user:{},
      path: this.$router.path //设置默认高亮的菜单
    }
  },
  created() {
    let userStr = sessionStorage.getItem("user") || "{}"
    this.user = JSON.parse(userStr)
    console.log(this.user.role)
    //由于这里的数据是从sessionStorage中获取的是用户可以修改的不可靠
    //因此还是要从后端请求数据
    request.get("/user/" + this.user.id).then(res => {
      if (res.code === '0'){
        this.user = res.data
      }
    })
  }
}
</script>

<style scoped>

</style>